
#include "MyPanel.h"

list<FSElement> Dir(const char* root2)
{
	list<FSElement> ElemList;

	WIN32_FIND_DATA fd;
	char root[260];
	strcpy(root,root2);
	strcat(root,"\\*");
	//strcpy(root,root2);
	//strcat(root,"\\*");
	HANDLE hFind=::FindFirstFile(root, &fd);
	//	HANDLE hFind=::FindFirstFile(root, &fd);
	//HANDLE hFind=::FindFirstFile(L"d:\\*", &fd);
	if(hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			char temp [255];
			sprintf(temp,"%s\n", fd.cFileName);
			int qq=strlen(temp);
			if (temp[strlen(temp)-1]==10)
				temp[strlen(temp)-1]=0;
			//printf("%s: %s\n", (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? "Folder" : "File", fd.cFileName);
			ElemList.push_back(FSElement(temp, fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));

		} while(::FindNextFile(hFind, &fd));

		::FindClose(hFind);
	}
	return ElemList;
}

void MyPanel::setDirectory( char* arg )
{
	strcpy(currentPath,arg);
	Elements.clear();
// 	char temp[255];
// 	strcpy(temp,arg);
// 	;
	Elements = Dir(currentPath);
	currentElem=Elements.begin();

}

void MyPanel::appendDirectory( char* arg )
{
	strcat(currentPath,"\\");
	setDirectory(strcat(currentPath,arg));

}

void MyPanel::enter()
{
	if ((*currentElem).isFolder)
		appendDirectory((*currentElem).name);

}

void MyPanel::goNext()
{
	 currentElem++;
}

void MyPanel::goPrev()
{
	currentElem--;
}